﻿function chooseColor(color){
	//Choose and show the new color
	debug.trace(color);
	color_code.value=color;
	this_color.background="#"+color;
}

function countToCheck(){
	if (color_code.value.length<6){
		return;
	}
	if (color_code.value.length>6){
		color_code.value=color_code.value.substring(0,6);
	}
	//Check if the typed value is hexadecimal
	if (isHexa(color_code.value)){
			chooseColor(color_code.value);
	}else{
			alert(INVALID_HEXA);
			color_code.value='FFFFFF';
			color_code.focus();
	}//End check
}

function isHexa(entry){
	validChar='0123456789ABCDEF'; //characters allowed in hex
	strlen=entry.length;
	if(strlen < 1){
		return false;
	}
	entry=entry.toUpperCase();
	//Scan for illegal chars
	for (i=0;i<strlen;i++){
		if(validChar.indexOf(entry.charAt(i))<0){
			return false;
		}
	} // end scanning loop
	return true;
}
